// pages/Index/transactionRecord/transactionRecord.js
const account=require("../../controllers/ControllerX").controller.account;
const accountList=require("../../controllers/ControllerX").controller.accountList;

const app=getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    accountData1:{},
    accountData2:{},
    accountData3:{},
    select1:true,
    select2:false,
    select3:false,
    select4:true,
    select5:false,
    //收入数据
    inputState:true,
    outputState:false,
    //展现的数据
    value:{
      pageNumber:1,
      pageSize:20,
      genre:'',
      shopId:"",
      type:'',
      lowLine:'',
      startTime:'',
      endTime:'',
    },
    lastPage:false,
    stateItem:"",
    shopImg:'',
    profitMoney1:"",
    profitMoney2:"",
    profitMoney3:"",
    incomeOrCost:['全部','收入','支出'],
    firstIndex:0,
    secondIndex:0,
    thiredIndex:0,
  },

  //重置
  resetData(){
    this.setData({
      'value.startTime':'',
      'value.endTime':'',
      'value.genre':'',
      firstIndex:0
    })
  },

  //跳转详情
  toDetail(e){

    let orderNo=e.currentTarget.dataset.orderno
    let genre=e.currentTarget.dataset.genre
    let type=e.currentTarget.dataset.type
    let name=e.currentTarget.dataset.name
    let head=e.currentTarget.dataset.head
    let accountId=e.currentTarget.dataset.accountid
  
    wx.navigateTo({
      url: '/pages/Index/transactionRecord/transactionDetails?orderNo='+orderNo+"&genre="+genre+"&type="+type+"&name="+name+"&head="+head+"&accountId="+accountId,
    })
  },

  getAccount(){
    var shopId=wx.getStorageSync('shopId');
    //全部收入支出
    account({shopId:shopId}).then(res=>{
      this.setData({
        accountData1:res.data,
        profitMoney1:(res.data.income-res.data.pay).toFixed(2)
      })
    })
  },


  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      'value.shopId':wx.getStorageSync('shopId')
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.getAccount();
    this.getAccountList();
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    this.getMore();
  },

  /**
   * 用户点击右上角分享
   */
   // onShareAppMessage: function () {

  // },
  //跳转提现记录
  jumpToInputHistory(){
    wx.navigateTo({
      url: '/pages/my/my_moneyInputHistory/index',
    })
  },
  //收入支出切换
  selectOutAndInput(event){
    let index=event.currentTarget.dataset.index;
    this.setData({
      firstIndex:index
    })
    let value=this.data.value
    if(index===0){
      value.genre=''
      value.type=''
      value.lowLine=''
      // this.setData({
      //   secondIndex:0
      // })
    }else if(index===1){
      value.genre=0
      value.type=''
      value.lowLine=''
      // this.setData({
      //   secondIndex:1
      // })
    } else{
      value.genre=1
      value.type=""
      value.lowLine=""
      // this.setData({
      //   thiredIndex:0
      // })
    }
    this.setData({
      value:value
    })
    this.getAccountList()
  },

  getAccountList(){
    this.setData({
      'value.pageNumber':1
    })
    accountList(this.data.value).then(res=>{
      this.setData({
        showList:res.data.page.list,
        lastPage:res.data.page.lastPage
      })
    })
  },

  //跳转提现
  jumpMoneyPut(){
    wx.navigateTo({
      url: '/pages/my/my_moneyPut/index',
    })
  },

  getMore(){
   if(this.data.lastPage==false){
    let value=this.data.value
    value.pageNumber=value.pageNumber+1
    this.setData({
      value:value
    })
    accountList(value).then(res=>{
      let list=this.data.showList
      let list2=res.data.page.list
      let list3=list.concat(list2)
      this.setData({
        showList:list3,
        lastPage:res.data.page.lastPage
      })
    })
   }
  },

   //改变开始时间
   bindStartChange(e){
    this.setData({
      'value.startTime':e.detail.value
    })
    this.getAccountList();
  },

  //改变结束时间
  bindEndChange(e){
    this.setData({
      'value.endTime':e.detail.value
    })
    this.getAccountList();
  }
})